package org.codeart.juc.thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class FutureDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask = new FutureTask<>(() -> {
            int ans = 0;
            for (int i = 1; i <= 100; i++) {
                ans += i;
            }
            Thread.sleep(2000);
            return ans;
        });
        Thread t1 = new Thread(futureTask);
        t1.start();
        // 调用 get 方法阻塞住
        Integer ans = futureTask.get();
        System.out.println(ans);
    }

}
